package com.hakim.wfb.sms.service.impl;

import com.hakim.wfb.sms.params.SendMsgParam;
import com.hakim.wfb.sms.service.api.SmsSendService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import utils.MsgSuDunUtils;
import utils.SmsClientSend;

/**
 * 短信发送服务类
 */
@Service("smsSendService")
public class SmsSendServiceImpl implements SmsSendService {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());


    @Override
    public boolean sendMsg(SendMsgParam param, String msg) {
        try {
            logger.info(" msg:{} ", msg);

            boolean bool = MsgSuDunUtils.batchSendMsg(new String[]{param.getMobilePhone()}, msg);

            return bool;

        } catch (Exception e) {

            e.printStackTrace();

            return false;
        }
    }

    private boolean isSmsSendSuccess(String response) {
        if (response != null) {
            response = response.replace("\n", ",");
            String[] array = response.split(",");
            if (array.length == 3) {
                return array[1].equals("0");
            }
        }
        return false;
    }

    @Override
    public boolean sendNote(String mobilePhone, String msg) {
        return false;
    }
}